/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dawnland02.model.task;

import dawnland02.model.entity.EntityInternal;

public abstract class Task {
    protected final String name; //the name of the task
    protected final EntityInternal entity; //the entity owner of this task

    protected GroupTask parentTask; //parent group task
    private TaskStatus taskStatus = TaskStatus.CREATED;

    public Task(String name, EntityInternal entity) {
        this.name = name;
        this.entity = entity;
    }

    public EntityInternal getEntity() {
        return entity;
    }

    public GroupTask getParentTask() {
        return parentTask;
    }

    protected final void setParentTask(GroupTask parentTask) {
        this.parentTask = parentTask;
    }

    public TaskStatus getTaskStatus() {
        return taskStatus;
    }

    public void setTaskStatus(TaskStatus taskStatus) {
        this.taskStatus = taskStatus;
    }

    protected final void executeNextTaskFromParent(){
        if(parentTask!=null){
            parentTask.executeNextSubtask();
        } else {
            entity.setDuringAction(false); //end of top most task;
        }
    }

    @Override
    public String toString() {        
        return name.substring(0,1);        
    }

    protected abstract void init();

    protected abstract void prepare();

    public abstract void execute();

    public abstract void end();

    public abstract boolean isGroupTask();

}
